/**
 * @ author: 汪孟苹
 */
define(["jquery","comm/toast/toast.ui"],function($,$toastUi){
	var toast = {};
    var className = "toast-showMessage";
    var confirmClassName = "toast-confirm";

    /**
     * 提示框 默认3500毫秒自动消失
     */
    toast.show = function(msg,time,callback,params){
        $("."+className).remove();
    	time = time ? time : 3500;
    	var h = '<div class="'+className+'">' + msg + '</div>';
    	$("body").append(h);
		var left = (- parseInt($("."+className).outerWidth() / 2) ) + 'px';
    	var top = (- parseInt($("."+className).outerHeight() / 2) ) + 'px';
    	$("."+className).css({
    		marginLeft: left,
    		marginTop: top,
    	});
    	timer = setTimeout(function(){
			$("."+className).remove();
		}, time);
        if(callback && typeof(callback) === "function"){
            setTimeout(function(){
                callback(params);
            }, time);
        }
    };
    toast.close = function(){
        $("."+className).remove();
    };

    /**
     * 确认框
     */
    toast.confirm = function(callback,params,tip){
        $(".toast-confirm-wrap").remove();
        $toastUi.confirmInit({
            confirmClassName:confirmClassName,
            tip:tip
        });
        var left = (- parseInt($("."+confirmClassName).outerWidth() / 2) ) + 'px';
        var top = (- parseInt($("."+confirmClassName).outerHeight() / 2) ) + 'px';
        $("."+confirmClassName).css({
            marginLeft: left,
            marginTop: top,
        });
        $("."+confirmClassName).find(".confirm").click(function(){
            $(".toast-confirm-wrap").remove();
            if(callback && typeof(callback) === "function"){
                callback(params);
            }
        });
        $("."+confirmClassName).find(".cancel").click(function(){
            $(".toast-confirm-wrap").remove();
        });
    }
    toast.confirmClose = function(){
        $(".toast-confirm-wrap").remove();
    };

    /**
     * 模态框
     *  id        模态框外包裹的box "modalBox"
     *  className 模态框class名
     *  size      模态框size  modal-lg  modal-sm  默认 正常的
     *  tit       模态框title
     */
    toast.modal = function(options,callback){
        var data = {
            "id":"modalBox",
            "className":"myModal",
        };
        $.extend(data,options);
        $toastUi.modal(data);
        if(callback && typeof(callback) === "function") callback();
    }

	return toast;
});